package cn.chengpengper.im.platform.common.utils;

import org.springframework.util.ReflectionUtils;

/*@formatter:off*/

/**
 * ____________________
 * < 神兽护体，永无bug! >
 * --------------------
 *
 * @author huchengpeng
 * @version v1.0.0
 * @date 2024/11/23 17:12
 * @description Bean 工具类
 */

/*@formatter:on*/

public class BeanUtils {

    private static void handleReflectionException(Exception e) {
        ReflectionUtils.handleReflectionException(e);
    }

    /**
     * 属性拷贝
     *
     * @param orig      源对象
     * @param destClass 目标
     * @return T
     */
    public static <T> T copyProperties(Object orig, Class<T> destClass) {
        try {
            if (orig == null) {
                return null;
            }
            Object target = destClass.newInstance();
            copyProperties(orig, target);
            return (T) target;
        } catch (Exception e) {
            handleReflectionException(e);
            return null;
        }
    }


    public static void copyProperties(Object orig, Object dest) {
        try {
            org.springframework.beans.BeanUtils.copyProperties(orig, dest);
        } catch (Exception e) {
            handleReflectionException(e);
        }
    }


}
